import time
from Common.Base import Base,open_browser

'''
Author:牟星林
'''

order_url = ("http://localhost:8080/Ecshop/")
class Order(Base):
    c_clothing =("link text","服装")
    c_buy = ("class name","price-btn")
    c_buy1 = ("css selector","#ECS_FORMBUY > ul > li.padd > table > tbody > tr > td.td1 > a > img")
    c_settlement = ("css selector","body > div:nth-child(7) > div:nth-child(3) > table > tbody > tr > td:nth-child(2) > a > img")
    c_sto = ("name","shipping")
    c_bank = ("css selector","#paymentTable > tbody > tr:nth-child(3) > td:nth-child(1) > input[type=radio]")
    c_submit = ("css selector","#theForm > div:nth-child(16) > div:nth-child(3) > input[type=image]:nth-child(1)")
    in_username = ("name","username")
    in_password = ("name","password")
    c_sign = ("name","login")
# 操作层
    def click_clothing(self):
        '''
        点击服装
        :return:
        '''
        self.click(self.c_clothing)

    def click_buy(self):
        '''
        点击购买
        :return:
        '''
        self.click(self.c_buy)

    def click_buy1(self):
        '''
        点击立即购买
        :return:
        '''
        self.click(self.c_buy1)

    def click_settlement(self):
        '''
        点击结算
        :return:
        '''
        self.click(self.c_settlement)

    def click_sto(self):
        '''
        选择中通快递
        :return:
        '''
        self.click(self.c_sto)

    def click_bank(self):
        '''
        选择银行支付
        :return:
        '''
        self.click(self.c_bank)

    def click_submit(self):
        '''
        提交订单
        :return:
        '''
        self.click(self.c_submit)

    def input_username(self,username):
        '''
        输入用户名
        :return:
        '''
        self.send_keys(self.in_username,username)

    def input_password(self,password):
        '''
        输入密码
        :param password:
        :return:
        '''
        self.send_keys(self.in_password,password)

    def click_sign(self):
        '''
        点击登录
        :return:
        '''
        self.click(self.c_sign)

if __name__ == '__main__':
    driver = open_browser()
    order = Order(driver)
    order.open_url("http://localhost:8080/Ecshop/")
    time.sleep(1)
    driver.maximize_window()

    order.click_clothing() # 点击服装
    time.sleep(1)

    order.click_buy() # 点击购买
    time.sleep(1)

    order.click_buy1() # 点击立即购买
    time.sleep(1)

    order.click_settlement() # 点击结算
    time.sleep(1)

    order.input_username("muxinglin") # 输入用户名
    time.sleep(1)

    order.input_password("mxl779208546") # 输入密码
    time.sleep(1)

    order.click_sign() # 点击登录
    time.sleep(1)


    order.click_sto() # 选择申通快递
    time.sleep(1)

    order.click_bank() # 选择银行支付
    time.sleep(1)

    order.click_submit() # 提交订单
    time.sleep(2)

    order.close_browser()




    

